Cope with corrupt or empty VDI config files. Have to_record return strings
authorEwan Mellor <ewan@xensource.com>
Mon, 25 Dec 2006 16:24:15 +0000 (16:24 +0000)
committerEwan Mellor <ewan@xensource.com>
Mon, 25 Dec 2006 16:24:15 +0000 (16:24 +0000)
rather than integers, as required by the Xen-API spec.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/python/xen/xend/XendStorageRepository.py

index adaa96f0053090ca4d1d6952d310c9bab7617780..42568e84a7c19e0d7c7848bd9afec5f76d3f1088 100644 (file)
@@ -103,16 +103,16 @@ class XendStorageRepository:
         retval = {'uuid': self.uuid,
                   'name_label': self.name_label,
                   'name_description': self.name_description,
-                  'virtual_allocation': self.storage_alloc,
-                  'physical_utilisation': self.storage_used,
-                  'physical_size': self.storage_max,
+                  'virtual_allocation': str(self.storage_alloc),
+                  'physical_utilisation': str(self.storage_used),
+                  'physical_size': str(self.storage_max),
                   'type': self.type,
                   'location': self.location,
                   'VDIs': self.images.keys()}
         
         if self.storage_max == XEND_STORAGE_NO_MAXIMUM:
             stfs = os.statvfs(self.location)
-            retval['physical_size'] = stfs.f_blocks * stfs.f_frsize
+            retval['physical_size'] = str(stfs.f_blocks * stfs.f_frsize)
 
         return retval
         
@@ -148,7 +148,11 @@ class XendStorageRepository:
                                           virt_size, phys_size)
                         
                         if cfg_path and os.path.exists(cfg_path):
-                            vdi.load_config(cfg_path)
+                            try:
+                                vdi.load_config(cfg_path)
+                            except:
+                                log.error('Corrupt VDI configuration file %s' %
+                                          cfg_path)
                         
                         self.images[image_uuid] = vdi